#pragma once
#include<unordered_map>
#include<vector>


#include "noncopyable.h"
#include "Timestamp.h"

// 相当于 抽象 select/poll/epoll

class EventLoop;
class Channel;

class Poller : Noncopyable{

public:

    using ChannelList = std::vector<Channel*>;
    Poller(EventLoop*);
    virtual ~Poller() = default;

    // 抽象函数
    virtual Timestamp poll(int timeout, ChannelList * activateChannels) = 0;
    virtual void updateChannel(Channel *c) = 0;
    virtual void removeChannel(Channel *c) = 0;

    // 判断参数channel是否在当前poller中
    bool hasChannel(Channel* channel) const;

    // 获取具体的poller（子类）
    static Poller* newDefaultPoller(EventLoop *loop);


protected:
    // k : fd. v: channel
    using ChannelMap = std::unordered_map<int, Channel*>;
    ChannelMap channels_;

private:
    EventLoop * ownerLoop_;  // 定义poller所属的eventloop

};
